package com.shaobufan.museum.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shaobufan.museum.mapper.CategoryMapper;
import com.shaobufan.museum.pojo.entity.Category;
import com.shaobufan.museum.pojo.vo.CategoryVo;
import com.shaobufan.museum.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 17126
 * &#064;description  针对表【museum_category(馆藏分类表)】的数据库操作Service实现
 * &#064;createDate  2024-03-12 20:46:34
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
        implements CategoryService {

    @Resource
    CategoryMapper categoryMapper;

    /**
     * 检索所有藏品类别
     *
     * @return 类别 List
     */
    @Override
    public List<CategoryVo> searchCategory() {
        List<Category> categoryList = categoryMapper.selectList(null);
        List<CategoryVo> categoryVoList;
        categoryVoList = categoryList.stream().map(this::getMuseumCategoryVo).collect(Collectors.toList());
        return categoryVoList;
    }


    /**
     * 按照馆藏类别 id查询 mane
     *
     * @param categoryId 馆藏类别id
     * @return CategoryVo
     */
    @Override
    public CategoryVo searchCategoryById(Integer categoryId){
        QueryWrapper<Category> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("category_id",categoryId);
        Category category = categoryMapper.selectOne(queryWrapper);
        return getMuseumCategoryVo(category);
    }


    /**
     * @param category 类别实体
     * @return museumCategoryVo
     */
    @Override
    public CategoryVo getMuseumCategoryVo(Category category) {

        CategoryVo categoryVo = new CategoryVo();
        categoryVo.setCategoryId(category.getCategoryId());
        categoryVo.setCategoryDetail(category.getCategoryDetail());

        return categoryVo;
    }
}